struct ListNode* removeElements(struct ListNode* head, int val){
    if(head == NULL){
        return NULL;
    }
    while(head != NULL && head -> val == val){
        struct ListNode*temp = head;
        head = head -> next;
        free(temp);
    }
    if(head == NULL || head -> next == NULL){ 
        //注意考虑指针为空或next为空的情况
        return head;
    }
    struct ListNode *pre = head;
    struct ListNode *p = head -> next;  //指向首节点
    while(p != NULL){
        if(p -> val == val){
            pre -> next = p -> next;
            struct ListNode *temp = p;  
            p = p -> next;
            free(temp);
        }
        else{
            pre = p;
            p = p -> next;
        }
    }
    return head;
}